﻿CREATE PROCEDURE [dbo].[usp_update_Message]
(
	 @MessageID				varchar (38)
	,@ResubmitAttempted		bit
	,@ResubmitSuccessful	bit
	,@Debug					bit = 1
)
AS

/****************************************************************************
Name: usp_update_Message.sql
Description:  Updates the ResubmitAttempted and ResubmitSuccessful flags for a message.
*****************************************************************************/
SET NOCOUNT ON;

-- Bootstrap
DECLARE @DebugPrefix       varchar(10);
DECLARE @ErrorCode         int;

SET @ErrorCode          = 0;
SET @DebugPrefix        = '>>> DEBUG: ';


-- Test harness
/*
DECLARE @Debug              bit;
DECLARE @MessageID			uniqueidentifier;
DECLARE @ResubmitAttempted  bit;
DECLARE @ResubmitSuccessful bit;

SELECT
	 @MessageID			= NEWID()		
	,@FaultID			= NEWID()	
	,@ResubmitAttempted = 1
	,@ResubmitSuccessful = 1
	,@Debug                 = 1;

*/

-- Print parameters
IF (@Debug > 0)
BEGIN
    PRINT @DebugPrefix + '@MessageID = ' + CAST(@MessageID AS varchar);
END;

UPDATE dbo.Message SET ResubmitAttempted = @ResubmitAttempted, ResubmitSuccessful =  @ResubmitSuccessful WHERE MessageID = CONVERT(varchar(38), @MessageID)

			
RETURN 0;

-- Handles errors.
ERROR_HANDLER:
IF (@ErrorCode <> 0)
BEGIN
    IF (@Debug > 0) 
		BEGIN
			PRINT @DebugPrefix + 'Error Code = ' + CAST(@ErrorCode AS varchar(10)) + ' occurred.';
			RETURN @ErrorCode
		END

    -- Don't return any evidence of what specific error occurred, i.e. 
    -- we want to ward off potential hackers.
    RETURN 1;
END;

SET NOCOUNT OFF;
